﻿set nocount on 
SET XACT_ABORT on 

declare @userid varchar(100) , @pwd varchar(100) ,@company varchar(100) , @token varchar(50)
set @userid = '{user}'
set @pwd = '{pwd}'
set @company = '{company}'


set @token = replace(newid(),'-','') 

INSERT INTO [dbo].[y_login]([login_company_key],[login_user_key],[create_time],[update_time],[token])
select u.company_key , user_key , getdate(), getdate(), @token
from y_user  u
inner join y_company c on u.company_key = c.company_key 
where u.user_id = @userid  and u.password = @pwd and  c.company_id = @company 

if @@rowcount =0 
	RAISERROR ('SQL:错误的用户名或密码', 16 ,1 ) ; 
	 
select user_key,user_name  , c.company_key ,company_name, @token as token
from y_user  u
inner join y_company c on u.company_key = c.company_key 
where u.user_id = @userid  and u.password = @pwd and  c.company_id = @company 

/*
select * from y_company
select * from y_user
*/



